package com.mzx.javase.io;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * 类描述：FileReader使用测试
 *
 * @ClassName FileReaderTest
 * @Description TODO
 * @Author 马子鑫
 * @Date 2022/7/21 10:57
 * @Version 1.0
 */
public class FileReaderTest {
    public static void main(String[] args) {
        FileReader reader = null;
        try {
            reader = new FileReader("D:\\java\\tempdirectory\\test01.txt");
            char[] chars = new char[4];
            int len = 0;
            while ((len = reader.read(chars)) != -1) {
                System.out.println(new String(chars,0,len));
            }
//            System.out.println((char) read);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

    }
}
